package main;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.Registration;
import com.esotericsoftware.kryo.io.ByteBufferOutput;
import com.esotericsoftware.kryo.io.FastOutput;
import com.esotericsoftware.kryo.io.Input;

public class KryoSerialize implements ISerialize{
	Kryo kryo = new Kryo();
	
	
//	private ByteBufferOutput output = new ByteBufferOutput(4096);
	
	private FastOutput output = new FastOutput(4096);

	@Override
	public byte[] serialize(Object obj) {
	    kryo.writeObject(output, obj);
	    byte[] b = output.toBytes();
	    output.clear();
		return b;
	}

	@Override
	public <T> T unSerialize(byte[] byts, Class<T> t) {
		Input input = new Input(byts); 
		return kryo.readObject(input, t);
	}
	
	
	
	
	

}
